Skip to content

Conversation

@jurahul
Copy link
Contributor

@jurahul jurahul commented Apr 4, 2025

  • Refactor INITIALIZE_PASS and INITIALIZE_PASS_WITH_OPTIONS macros to eliminate some code duplication.

- Refactor INITIALIZE_PASS and INITIALIZE_PASS_WITH_OPTIONS macros
  to eliminate some code duplication.
@jurahul jurahul marked this pull request as ready for review April 4, 2025 23:17
@jurahul jurahul requested review from bogner and nikic April 4, 2025 23:17
@llvmbot
Copy link
Member

llvmbot commented Apr 4, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Rahul Joshi (jurahul)

Changes
  • Refactor INITIALIZE_PASS and INITIALIZE_PASS_WITH_OPTIONS macros to eliminate some code duplication.

Full diff: https://github.com/llvm/llvm-project/pull/134457.diff

1 Files Affected:

  • (modified) llvm/include/llvm/PassSupport.h (+7-18)
diff --git a/llvm/include/llvm/PassSupport.h b/llvm/include/llvm/PassSupport.h
index d3ba32f22efe1..57210b2488b53 100644
--- a/llvm/include/llvm/PassSupport.h
+++ b/llvm/include/llvm/PassSupport.h
@@ -35,20 +35,6 @@ namespace llvm {
 
 class Pass;
 
-#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)                    \
-  static void *initialize##passName##PassOnce(PassRegistry &Registry) {        \
-    PassInfo *PI = new PassInfo(                                               \
-        name, arg, &passName::ID,                                              \
-        PassInfo::NormalCtor_t(callDefaultCtor<passName>), cfg, analysis);     \
-    Registry.registerPass(*PI, true);                                          \
-    return PI;                                                                 \
-  }                                                                            \
-  static llvm::once_flag Initialize##passName##PassFlag;                       \
-  void llvm::initialize##passName##Pass(PassRegistry &Registry) {              \
-    llvm::call_once(Initialize##passName##PassFlag,                            \
-                    initialize##passName##PassOnce, std::ref(Registry));       \
-  }
-
 #define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)              \
   static void *initialize##passName##PassOnce(PassRegistry &Registry) {
 
@@ -67,15 +53,18 @@ class Pass;
                     initialize##passName##PassOnce, std::ref(Registry));       \
   }
 
-#define INITIALIZE_PASS_WITH_OPTIONS(PassName, Arg, Name, Cfg, Analysis)       \
-  INITIALIZE_PASS_BEGIN(PassName, Arg, Name, Cfg, Analysis)                    \
-  PassName::registerOptions();                                                 \
-  INITIALIZE_PASS_END(PassName, Arg, Name, Cfg, Analysis)
+#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)                    \
+  INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)                    \
+  INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
 
 #define INITIALIZE_PASS_WITH_OPTIONS_BEGIN(PassName, Arg, Name, Cfg, Analysis) \
   INITIALIZE_PASS_BEGIN(PassName, Arg, Name, Cfg, Analysis)                    \
   PassName::registerOptions();
 
+#define INITIALIZE_PASS_WITH_OPTIONS(PassName, Arg, Name, Cfg, Analysis)       \
+  INITIALIZE_PASS_WITH_OPTIONS_BEGIN(PassName, Arg, Name, Cfg, Analysis)       \
+  INITIALIZE_PASS_END(PassName, Arg, Name, Cfg, Analysis)
+
 template <
     class PassName,
     std::enable_if_t<std::is_default_constructible<PassName>{}, bool> = true>

@jurahul jurahul merged commit 6ac5cbd into llvm:main Apr 5, 2025
15 checks passed
@jurahul jurahul deleted the refactor_initialize_pass branch April 5, 2025 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants